from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-09 14:04:03.508212
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 09, Oct, 2022
Time: 14:04:10
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.6524
Nobs: 804.000 HQIC: -50.9757
Log likelihood: 10395.9 FPE: 5.94239e-23
AIC: -51.1774 Det(Omega_mle): 5.31675e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296953 0.052779 5.626 0.000
L1.Burgenland 0.109230 0.035496 3.077 0.002
L1.Kärnten -0.106416 0.018900 -5.631 0.000
L1.Niederösterreich 0.210200 0.074240 2.831 0.005
L1.Oberösterreich 0.100041 0.071220 1.405 0.160
L1.Salzburg 0.251577 0.037847 6.647 0.000
L1.Steiermark 0.038170 0.049518 0.771 0.441
L1.Tirol 0.106275 0.040155 2.647 0.008
L1.Vorarlberg -0.059208 0.034518 -1.715 0.086
L1.Wien 0.057722 0.063600 0.908 0.364
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064250 0.109274 0.588 0.557
L1.Burgenland -0.033614 0.073491 -0.457 0.647
L1.Kärnten 0.047831 0.039130 1.222 0.222
L1.Niederösterreich -0.172379 0.153708 -1.121 0.262
L1.Oberösterreich 0.385189 0.147455 2.612 0.009
L1.Salzburg 0.287226 0.078359 3.666 0.000
L1.Steiermark 0.106078 0.102523 1.035 0.301
L1.Tirol 0.313452 0.083138 3.770 0.000
L1.Vorarlberg 0.025237 0.071467 0.353 0.724
L1.Wien -0.016622 0.131679 -0.126 0.900
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189941 0.027094 7.010 0.000
L1.Burgenland 0.090122 0.018222 4.946 0.000
L1.Kärnten -0.008446 0.009702 -0.870 0.384
L1.Niederösterreich 0.264461 0.038112 6.939 0.000
L1.Oberösterreich 0.126571 0.036561 3.462 0.001
L1.Salzburg 0.047490 0.019429 2.444 0.015
L1.Steiermark 0.016893 0.025420 0.665 0.506
L1.Tirol 0.094285 0.020614 4.574 0.000
L1.Vorarlberg 0.059350 0.017720 3.349 0.001
L1.Wien 0.120389 0.032650 3.687 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110038 0.027769 3.963 0.000
L1.Burgenland 0.044252 0.018675 2.370 0.018
L1.Kärnten -0.016093 0.009944 -1.618 0.106
L1.Niederösterreich 0.193046 0.039060 4.942 0.000
L1.Oberösterreich 0.294249 0.037471 7.853 0.000
L1.Salzburg 0.115093 0.019913 5.780 0.000
L1.Steiermark 0.099804 0.026053 3.831 0.000
L1.Tirol 0.116289 0.021127 5.504 0.000
L1.Vorarlberg 0.070638 0.018161 3.889 0.000
L1.Wien -0.027695 0.033462 -0.828 0.408
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128821 0.050350 2.559 0.011
L1.Burgenland -0.051142 0.033862 -1.510 0.131
L1.Kärnten -0.040283 0.018030 -2.234 0.025
L1.Niederösterreich 0.170617 0.070824 2.409 0.016
L1.Oberösterreich 0.137263 0.067943 2.020 0.043
L1.Salzburg 0.285732 0.036105 7.914 0.000
L1.Steiermark 0.034935 0.047239 0.740 0.460
L1.Tirol 0.164178 0.038307 4.286 0.000
L1.Vorarlberg 0.103725 0.032930 3.150 0.002
L1.Wien 0.068438 0.060674 1.128 0.259
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060044 0.039921 1.504 0.133
L1.Burgenland 0.038536 0.026848 1.435 0.151
L1.Kärnten 0.050656 0.014295 3.544 0.000
L1.Niederösterreich 0.225944 0.056154 4.024 0.000
L1.Oberösterreich 0.282117 0.053869 5.237 0.000
L1.Salzburg 0.050837 0.028627 1.776 0.076
L1.Steiermark -0.007120 0.037454 -0.190 0.849
L1.Tirol 0.149827 0.030372 4.933 0.000
L1.Vorarlberg 0.070934 0.026109 2.717 0.007
L1.Wien 0.079178 0.048106 1.646 0.100
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178698 0.047714 3.745 0.000
L1.Burgenland -0.005847 0.032089 -0.182 0.855
L1.Kärnten -0.061087 0.017086 -3.575 0.000
L1.Niederösterreich -0.083477 0.067116 -1.244 0.214
L1.Oberösterreich 0.192616 0.064385 2.992 0.003
L1.Salzburg 0.056697 0.034215 1.657 0.098
L1.Steiermark 0.230870 0.044766 5.157 0.000
L1.Tirol 0.493648 0.036302 13.598 0.000
L1.Vorarlberg 0.049419 0.031206 1.584 0.113
L1.Wien -0.049171 0.057497 -0.855 0.392
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162207 0.054793 2.960 0.003
L1.Burgenland -0.011402 0.036850 -0.309 0.757
L1.Kärnten 0.065970 0.019621 3.362 0.001
L1.Niederösterreich 0.200706 0.077074 2.604 0.009
L1.Oberösterreich -0.061161 0.073938 -0.827 0.408
L1.Salzburg 0.216129 0.039291 5.501 0.000
L1.Steiermark 0.113828 0.051408 2.214 0.027
L1.Tirol 0.076850 0.041688 1.843 0.065
L1.Vorarlberg 0.124422 0.035836 3.472 0.001
L1.Wien 0.114569 0.066027 1.735 0.083
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353990 0.031880 11.104 0.000
L1.Burgenland 0.006136 0.021440 0.286 0.775
L1.Kärnten -0.023554 0.011416 -2.063 0.039
L1.Niederösterreich 0.223991 0.044843 4.995 0.000
L1.Oberösterreich 0.175387 0.043019 4.077 0.000
L1.Salzburg 0.046936 0.022861 2.053 0.040
L1.Steiermark -0.017195 0.029910 -0.575 0.565
L1.Tirol 0.108586 0.024255 4.477 0.000
L1.Vorarlberg 0.073515 0.020850 3.526 0.000
L1.Wien 0.053552 0.038416 1.394 0.163
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041139 0.152746 0.190307 0.157124 0.125069 0.113804 0.065648 0.226957
Kärnten 0.041139 1.000000 -0.002515 0.129727 0.041407 0.096103 0.429679 -0.053121 0.101364
Niederösterreich 0.152746 -0.002515 1.000000 0.337096 0.155114 0.300458 0.111045 0.183841 0.327621
Oberösterreich 0.190307 0.129727 0.337096 1.000000 0.232319 0.332724 0.172541 0.172507 0.263122
Salzburg 0.157124 0.041407 0.155114 0.232319 1.000000 0.146586 0.126846 0.148891 0.135548
Steiermark 0.125069 0.096103 0.300458 0.332724 0.146586 1.000000 0.153435 0.141020 0.079782
Tirol 0.113804 0.429679 0.111045 0.172541 0.126846 0.153435 1.000000 0.114827 0.155031
Vorarlberg 0.065648 -0.053121 0.183841 0.172507 0.148891 0.141020 0.114827 1.000000 0.007192
Wien 0.226957 0.101364 0.327621 0.263122 0.135548 0.079782 0.155031 0.007192 1.000000